package com.info.zhiduoduo.admin.controller;

import com.info.zhiduoduo.admin.model.formbean.project.ProjectListFormBean;
import com.info.zhiduoduo.admin.model.formbean.system.BusinessManagerFormBean;
import com.info.zhiduoduo.admin.model.formbean.system.SaveBusinessManagerFormBean;
import com.info.zhiduoduo.admin.service.BusinessManagerService;
import com.info.zhiduoduo.common.annotation.LogEntity;
import com.info.zhiduoduo.common.annotation.LogParameter;
import com.info.zhiduoduo.common.annotation.ZddLog;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.system.ZddLogType;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;

import com.info.zhiduoduo.repository.dto.system.QueryBusinessManagerDto;
import com.info.zhiduoduo.repository.entity.system.BusinessManager;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@RestController
@RequestMapping("/businessManager")
public class BusinessManagerController {

    @Autowired
    BusinessManagerService businessManagerService;

    //新增商务经理
    @ZddLog(name = "新增商户经理")
    @PostMapping("/saveBusinessManager")
    public SmartResult saveBusinessManager(@RequestBody BaseSimpleFormBean<SaveBusinessManagerFormBean> formBean){
        return businessManagerService.saveBusinessManager(formBean);
    }

    //修改商务经理
    @ZddLog(type = ZddLogType.UPDATE,name = "修改商务经理",entities = @LogEntity(entity = BusinessManager.class,parameters =
    @LogParameter(fields = "businessManagerId",parameters = "formBean.reqdata.businessManagerId")))
    @PostMapping("/updateBusinessManager")
    public SmartResult updateBusinessManager(@RequestBody BaseSimpleFormBean<BusinessManagerFormBean> formBean){
        return businessManagerService.updateBusinessManager(formBean);
    }

    //删除商务经理（逻辑删除）
    @ZddLog(type = ZddLogType.DELETE,name = "逻辑删除商务经理",entities = @LogEntity(entity = BusinessManager.class,parameters =
    @LogParameter(fields = "businessManagerId",parameters = "formBean.reqdata.businessManagerId")))
    @PostMapping("/delBusinessManager")
    public SmartResult delBusinessManager(@RequestBody BaseSimpleFormBean<BusinessManagerFormBean> formBean){
        return businessManagerService.delBusinessManager(formBean);
    }

    //查询所有正常状态的商务经理（带分页）
    @PostMapping("/queryBusinessManager")
    @ResponseBody
    public SmartResult queryBusinessManager(@RequestBody BaseSimpleFormBean<QueryBusinessManagerDto> formBean){
        return businessManagerService.queryBusinessManager(formBean);
    }

    //查询所有的商务经理（不带分页）
    @PostMapping("/queryAllBusinessManager")
    @ResponseBody
    public SmartResult queryAllBusinessManager(@RequestBody BaseSimpleFormBean<QueryBusinessManagerDto> formBean){
        return businessManagerService.queryAllBusinessManager(formBean);
    }
    @ApiOperation(value = "下载创客项目列表", tags = "下载excel")
    @GetMapping("exportBusinessManager")
    public void exportBusinessManager(HttpServletResponse response,
                                    @ApiParam(name = "name", value = "模糊搜索商务经理") @RequestParam(name = "name", required = false) String name,
                                    @ApiParam(name = "years", value = "年月") @RequestParam(name = "years", required = false) Long years){
        Date yearss = null;
        if (years != null) {
            yearss = new Date(years);
        }
        businessManagerService.exportBusinessManager(response,yearss,name);

    }
}
